package cn.daniel.user.controller;


import cn.daniel.commonutils.Response;
import cn.daniel.user.entity.User;
import cn.daniel.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Daniel_li
 * @since 2020-12-25
 */
@RestController
@RequestMapping("/service/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户集合
     * @return
     */
    @GetMapping("/getUserList")
    public Response getUserList(){
        List<User> list = userService.list(null);
        return Response.ok().data("userList",list);
    }

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @GetMapping("/getUserOne/{id}")
    public Response getUserOne(@PathVariable String id){
        User user = userService.getById(id);
        return Response.ok().data("user",user);
    }

    @PostMapping("/addUser")
    public Response addUser(@RequestBody User user){
        boolean save = userService.save(user);
        return save? Response.ok():Response.error();
    }
    @DeleteMapping("/removeUserById/{id}")
    public Response removeUserById(@PathVariable String id){
        boolean b = userService.removeById(id);
        return b? Response.ok():Response.error();
    }






}

